home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / ImmortalDesendants / WINDOWS / Desktop / ID Site / search.cgi < prev    next >
Encoding:
Text File  |  2000-05-25  |  11.2 KB  |  293 lines

  1. #!/usr/bin/perl
  2.  
  3. ##############################################################################
  4. # Revved Search                        Version 1.0                           #
  5. # Copyright 1998 Rev Ventures, Inc.    info@revved.com                       #
  6. # Created 08/08/98                     Last Modified 08/08/98                #
  7. # Software Archive at:                 http://www.revved.com                 #
  8. ##############################################################################
  9. # COPYRIGHT NOTICE                                                           #
  10. # Copyright 1998 Rev Ventures, Inc. All Rights Reserved.                     #
  11. #                                                                            #
  12. # Revved Search may be used and modified free of charge by anyone so long as #
  13. # this copyright notice and the comments above remain intact.  By using this #
  14. # code you agree to indemnify Rev Ventures, Inc. from any liability that     #  
  15. # might arise from it's use.                                                 #  
  16. #                                                                            #
  17. # Selling this program's code without prior written consent is expressly     #
  18. # forbidden.                                                                 #
  19. #                                                                            #
  20. # Obtain permission before redistributing this software over the Internet or #
  21. # in any other medium.  In all cases copyright and header must remain intact.#
  22. ##############################################################################
  23. # Define core information:                                                   #
  24.  
  25. $domain = "http://www.immortaldescendants.com";
  26. $mainpath = "/usr/local/etc/httpd/htdocs/immortaldescendantscom";
  27. @folders = "";
  28. $exclusions = "";
  29.  
  30.  
  31. ##############################################################################
  32.  
  33.  
  34.  
  35.  
  36. &ParseInput;
  37. print "Content-type: text/html\n\n";
  38.  
  39. if ($in{'keys'} && $in{'prc'}) {
  40.  
  41.      if ($in{'background'}) { $bg = "BACKGROUND=\"$in{'background'}\""; }
  42.      print "<HTML><HEAD><TITLE>$in{'title'}</TITLE></HEAD>\n";
  43.      print "<BODY BGCOLOR=\"$in{'bgcolor'}\" $bg TEXT=\"$in{'textcolor'}\" LINK=\"$in{'linkcolor'}\" VLINK=\"$in{'vlinkcolor'}\"><CENTER>";
  44.      if ($in{'header'}) { 
  45.             @head = split(/,/, $in{'header'});
  46.             print "<IMG SRC=\"$head[0]\" WIDTH=\"$head[1]\" HEIGHT=\"$head[2]\"><P>\n"; 
  47.             }
  48.      print "<TABLE CELLPADDING=0 CELLSPACING=0 BORDER=0 WIDTH=80\%><TR><TD>\n";
  49.  
  50.      $a = 0;
  51.  
  52.      unless ($folders[0]) {
  53.      $folders[0] = "$mainpath";
  54.  
  55.      do {
  56.  
  57.           $first = shift (@folders);
  58.           $paths[$a] = "$first";
  59.           $a++;
  60.           opendir(ROOMDIR, "$first");
  61.           @hunts = sort(readdir(ROOMDIR));
  62.           closedir(ROOMDIR);
  63.           foreach $hunt(@hunts) {  
  64.  
  65.                     $set = "$first/$hunt";
  66.                     if ((-d "$set") && ($hunt ne ".") && ($hunt ne "..")) { unless ($exclusions =~ /\,$set\,/) {  push (@folders, "$set"); }  }                   
  67.  
  68.                     }
  69.  
  70.      } until ($first eq "");
  71.      }
  72.  
  73.      $act = 0;
  74.      $s = 0;
  75.      $c = 0;
  76.  
  77.      unless ($in{'L'} && $in{'H'}) { $in{'L'} = 1;  $in{'H'} = 10; }
  78.      $verf = $in{'L'};
  79.  
  80.      $nL = ($in{'H'} + 1);
  81.      $nH = ($in{'H'} + 10);
  82.      $pL = ($in{'L'} - 10);
  83.      $pH = ($in{'H'} - 10);
  84.  
  85.      unless ($in{'prc'} eq "exact") {
  86.  
  87.            $in{'keys'} =~ s/\Wand\W/ /gi;
  88.            $in{'keys'} =~ s/\Wor\W/ /gi;
  89.            $in{'keys'} =~ s/\Wand\W/ /gi;
  90.            $in{'keys'} =~ s/\Wor\W/ /gi;
  91.            $in{'keys'} =~ s/\,/\, \,/gi;
  92.            $in{'keys'} =~ s/\,//gi;
  93.            $in{'keys'} =~ s/\+//gi;
  94.            $in{'keys'} =~ s/  / /gi;
  95.            if ($in{'keys'} =~ / /) { @keys = split(/ /,$in{'keys'}); } else { $keys[0] = $in{'keys'}; }
  96.            foreach $key(@keys) { if ($key) { $act++; }  }
  97.  
  98.            if ($in{'keys'} eq "") { print "<B>The search you are attempting is too vague. Please try again.</B></TD></TR></TABLE>"; exit; }
  99.  
  100.            }
  101.  
  102.  
  103.   foreach $path(@paths) {
  104.  
  105.      $relpath = $path;
  106.      $relpath =~ s/$mainpath\///gi;
  107.      $relpath =~ s/$mainpath//gi;
  108.  
  109.      opendir(ROOMDIR, "$path");
  110.      @files = sort(readdir(ROOMDIR));
  111.      closedir(ROOMDIR);
  112.  
  113.      foreach $file(@files) {
  114.  
  115.         if (-T "$path/$file") {
  116.             open (DOC, "$path/$file");
  117.             $add = "no";
  118.             $inibuff = "";
  119.             $finbuff = "";
  120.             do { 
  121.  
  122.                    $line = <DOC>; 
  123.                    $inibuff .= $line;
  124.  
  125.                 } until ($line eq "");
  126.  
  127.             close (DOC);
  128.  
  129.             $inibuff =~ s/\n/ /i;
  130.             $inibuff =~ s/\ \;//gi; 
  131.  
  132.             if (($inibuff =~ /<TITLE>/i) && ($inibuff =~ /<\/TITLE>/i)) {
  133.  
  134.                  @step1 = split(/<TITLE>/i, $inibuff);
  135.                  @step2 = split(/<\/TITLE>/i, $step1[1]);
  136.                  $header = $step2[0];
  137.                  $inibuff =~ s/<TITLE>.*\<\/TITLE>//i;
  138.  
  139.                   }
  140.  
  141.             @fltr1 = split(/</, $inibuff);
  142.             $inibuff = "";
  143.             foreach $lcarr(@fltr1) { 
  144.  
  145.                              if ($lcarr =~ />/) { @fltr2 = split(/>/, $lcarr); $inibuff .= $fltr2[1]; }
  146.                              else { $inibuff .= $lcarr; }
  147.  
  148.                            }
  149.  
  150.  
  151.             if ($in{'prc'} eq "any") { 
  152.  
  153.                      $comp = 0;
  154.                      foreach $key(@keys) { if ($key) { if (($inibuff =~ /\W$key\W/i) || ($header =~ /\W$key\W/i)) { $comp++; } } }
  155.                      if ($comp > 0) { $add = "yes"; $ttl++; }
  156.  
  157.                      }
  158.  
  159.             if ($in{'prc'} eq "all") { 
  160.  
  161.                      $comp = 0;
  162.                      foreach $key(@keys) { if ($key) { if (($inibuff =~ /\W$key\W/i) || ($header =~ /\W$key\W/i)) { $comp++; } } }
  163.                      if ($comp >= $act) { $add = "yes"; $ttl++; }
  164.  
  165.                      }
  166.  
  167.             if ($in{'prc'} eq "exact") { 
  168.  
  169.                      if ($inibuff =~ /\W$in{'keys'}\W/i) { $add = "yes"; $ttl++; }  
  170.  
  171.                      }
  172.  
  173.             if ($add eq "yes") { $s++; }
  174.  
  175.             if (($add eq "yes") && ($s >= $in{'L'})) {
  176.  
  177.               unless ($s > $in{'H'}) {
  178.  
  179.                 @fltr1 = split(/ /, $inibuff);
  180.                 $inibuff = "";
  181.                 $i = 0;
  182.                 $stp = @fltr1;
  183.  
  184.                 do {
  185.  
  186.                      $inibuff .= " $fltr1[$i]";
  187.                      $lgth = length($inibuff);
  188.                      $i++;
  189.  
  190.                      } until (($lgth >= 200) || ($i > $stp));
  191.  
  192.                 if ($relpath) { $fs = "\/"; } else { $fs = ""; }
  193.                 if ($header) { $result[$c] = "<A HREF=\"\/$relpath$fs$file\">$header</A><BR><FONT SIZE=2>$inibuff . . .\n</FONT><P>\n"; }
  194.                  else { $result[$c] =  "<A HREF=\"\/$relpath$fs$file\">$domain\/$file</A><BR><FONT SIZE=2>$inibuff . . .\n</FONT><P>\n";  }
  195.  
  196.                 $verf++;
  197.                 $c++;
  198.  
  199.               }
  200.  
  201.              }
  202.  
  203.           } 
  204.  
  205.       }
  206.  
  207.   }
  208.  
  209.  
  210.  
  211.  
  212.  
  213.    --$verf;
  214.  
  215.    splice (@result, 10, 1);
  216.  
  217.    if ($verf <= 0) { print "<B><FONT SIZE=4>Sorry. No pages matched your search.<BR><BR>";   &PrintForm;  exit; }
  218.    if ($in{'L'} == $verf) { print "<FONT SIZE=4><B>Search Results:</FONT></B><BR>Match $verf</B><HR><BR>"; }
  219.    else { print "<FONT SIZE=4><B>Search Results:</FONT></B><BR>Matches $in{'L'} \- $verf out of $ttl</B><HR><BR>"; }
  220.  
  221.    foreach $match(@result) { print "$match"; }
  222.    print "<HR><CENTER><TABLE CELLPADDING=4 CELLSPACING=0 BORDER=0><TR>";
  223.    
  224.    unless ($in{'H'} < 11) { print "<TD><FORM METHOD=\"post\" ACTION=\"search.cgi\"><INPUT TYPE=\"hidden\" NAME=\"keys\" VALUE=\"$in{'keys'}\"><INPUT TYPE=\"hidden\" NAME=\"L\" VALUE=\"$pL\"><INPUT TYPE=\"hidden\" NAME=\"H\" VALUE=\"$pH\"><INPUT TYPE=\"hidden\" NAME=\"prc\" VALUE=\"$in{'prc'}\"><INPUT TYPE=\"hidden\" NAME=\"title\" VALUE=\"$in{'title'}\"><INPUT TYPE=\"hidden\" NAME=\"header\" VALUE=\"$in{'header'}\"><INPUT TYPE=\"hidden\" NAME=\"bgcolor\" VALUE=\"$in{'bgcolor'}\"><INPUT TYPE=\"hidden\" NAME=\"background\" VALUE=\"$in{'background'}\"><INPUT TYPE=\"hidden\" NAME=\"textcolor\" VALUE=\"$in{'textcolor'}\"><INPUT TYPE=\"hidden\" NAME=\"linkcolor\" VALUE=\"$in{'linkcolor'}\"><INPUT TYPE=\"hidden\" NAME=\"vlinkcolor\" VALUE=\"$in{'vlinkcolor'}\"><INPUT TYPE=\"submit\" VALUE=\"Previous Matches\"></FORM></TD>"; }
  225.  
  226.   unless ($ttl == $verf) { print "<TD><FORM METHOD=\"post\" ACTION=\"search.cgi\"><INPUT TYPE=\"hidden\" NAME=\"keys\" VALUE=\"$in{'keys'}\"><INPUT TYPE=\"hidden\" NAME=\"L\" VALUE=\"$nL\"><INPUT TYPE=\"hidden\" NAME=\"H\" VALUE=\"$nH\"><INPUT TYPE=\"hidden\" NAME=\"prc\" VALUE=\"$in{'prc'}\"><INPUT TYPE=\"hidden\" NAME=\"title\" VALUE=\"$in{'title'}\"><INPUT TYPE=\"hidden\" NAME=\"header\" VALUE=\"$in{'header'}\"><INPUT TYPE=\"hidden\" NAME=\"bgcolor\" VALUE=\"$in{'bgcolor'}\"><INPUT TYPE=\"hidden\" NAME=\"background\" VALUE=\"$in{'background'}\"><INPUT TYPE=\"hidden\" NAME=\"textcolor\" VALUE=\"$in{'textcolor'}\"><INPUT TYPE=\"hidden\" NAME=\"linkcolor\" VALUE=\"$in{'linkcolor'}\"><INPUT TYPE=\"hidden\" NAME=\"vlinkcolor\" VALUE=\"$in{'vlinkcolor'}\"><INPUT TYPE=\"submit\" VALUE=\"More Matches\"></FORM></TD>"; }
  227.  
  228.   print "</TR></TABLE><HR>";
  229.   &PrintForm;
  230.  
  231.  
  232. }
  233.  
  234. else {
  235.  
  236.      print "<HTML><HEAD><TITLE>Error in search attempt</TITLE></HEAD><BODY BGCOLOR=\"FFFFFF\"><BR><BR><BLOCKQUOTE><FONT SIZE=4><B>ERROR:</B></FONT> You have not entered any search criteria. Please press <B>BACK</B> on your browser and try again.</BODY>\n</HTML>";
  237.  
  238. }
  239.  
  240.  
  241. sub ParseInput {
  242.  
  243.    if ($ENV{'REQUEST_METHOD'} eq 'GET') {
  244.       @pairs = split(/&/, $ENV{'QUERY_STRING'});
  245.    }
  246.    elsif ($ENV{'REQUEST_METHOD'} eq 'POST') {
  247.       read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
  248.  
  249.       @pairs = split(/&/, $buffer);
  250.    }
  251.    else {
  252.       &error('request_method');
  253.    }
  254.  
  255.    foreach $pair (@pairs) {
  256.       ($name, $value) = split(/=/, $pair);
  257.  
  258.       $name =~ tr/+/ /;
  259.       $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
  260.  
  261.       $value =~ tr/+/ /;
  262.       $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
  263.  
  264.       $value =~ s/<!--(.|\n)*-->//g;
  265.     
  266.       if ($name && $value) { $in{$name} = $value; }
  267.    
  268.    }
  269.  
  270. }
  271.  
  272.  
  273. sub PrintForm {
  274.  
  275.      print "<BR></CENTER><FORM METHOD=\"post\" ACTION=\"search.cgi\">
  276. <TABLE CELLPADDING=2 CELLSPACING=0 BORDER=0><TR><TD COLSPAN=3><B><FONT SIZE=4>Search again:</FONT></B></TD></TR><TR><TD>search for:</TD><TD><INPUT TYPE=\"text\" NAME=\"keys\" SIZE=20></TD><TD><INPUT TYPE=\"submit\" VALUE=\"Search\"></TD></TR><TR><TD ALIGN=\"right\">match:</TD><TD COLSPAN=2><SELECT NAME=\"prc\" SIZE=1>
  277. <OPTION SELECTED VALUE=\"any\">any of the words
  278. <OPTION VALUE=\"all\">all of the words
  279. <OPTION VALUE=\"exact\">the exact phrase
  280. </SELECT></TD></TR></TABLE>
  281. <INPUT TYPE=\"hidden\" NAME=\"title\" VALUE=\"$in{'title'}\">
  282. <INPUT TYPE=\"hidden\" NAME=\"header\" VALUE=\"$in{'header'}\">
  283. <INPUT TYPE=\"hidden\" NAME=\"bgcolor\" VALUE=\"$in{'bgcolor'}\">
  284. <INPUT TYPE=\"hidden\" NAME=\"background\" VALUE=\"$in{'background'}\">
  285. <INPUT TYPE=\"hidden\" NAME=\"textcolor\" VALUE=\"$in{'textcolor'}\">
  286. <INPUT TYPE=\"hidden\" NAME=\"linkcolor\" VALUE=\"$in{'linkcolor'}\">
  287. <INPUT TYPE=\"hidden\" NAME=\"vlinkcolor\" VALUE=\"$in{'vlinkcolor'}\">
  288. </FORM></TD></TR></TABLE>\n</BODY>\n</HTML>";
  289.  
  290.  
  291. }
  292.  
  293.